const { DataTypes } = require('sequelize');
const { sequelize } = require('../config/database');

// 定义 Category 模型
const Category = sequelize.define('Category', {
  id: {
    type: DataTypes.INTEGER,
    primaryKey: true,
    autoIncrement: true,
    comment: '分类ID'
  },
  name: {
    type: DataTypes.STRING(50),
    allowNull: false,
    unique: true,
    validate: {
      notNull: {
        msg: '分类名称不能为空'
      },
      notEmpty: {
        msg: '分类名称不能为空'
      }
    },
    comment: '分类名称'
  },
  description: {
    type: DataTypes.STRING(200),
    allowNull: true,
    comment: '分类描述'
  },
  icon: {
    type: DataTypes.STRING(50),
    allowNull: true,
    comment: '分类图标'
  },
  created_at: {
    type: DataTypes.DATE,
    defaultValue: DataTypes.NOW,
    field: 'created_at'
  },
  updated_at: {
    type: DataTypes.DATE,
    defaultValue: DataTypes.NOW,
    field: 'updated_at'
  }
}, {
  tableName: 'categories',
  timestamps: true,
  createdAt: 'created_at',
  updatedAt: 'updated_at'
});

module.exports = Category;

